/**
 * Copyright 2011 Joe Choi, All rights reserved.
 */
package tec.data.structure;

import java.util.ArrayDeque;
import java.util.Deque;
import java.util.NoSuchElementException;

import tao.data.structure.Stack;

/**
 * The concrete implementation of Stack interface
 * 
 * @author Joe Choi
 */
class ConcreteStack<T> implements Stack<T> {
	public ConcreteStack() {
		stack = new ArrayDeque<T>();
	}
	
	public ConcreteStack(Stack<T> stack) {
		
	}
	
	@Override
	public boolean isEmpty() {
		return(stack.isEmpty());
	}

	@Override
	public T pop() {
		try {
			return(stack.pop());
		} catch(NoSuchElementException e) {
			return(null);
		}
	}

	@Override
	public void push(T data) {
		stack.push(data);
	}

	@Override
	public int size() {
		return(stack.size());
	}

	@Override
	public T top() {
		return(stack.peek());
	}
	
	@Override
	public String toString() {
		return(stack.toString());
	}
	
	@Override
	public boolean equals(Object obj) {
		if((obj == null) || (!(obj instanceof ConcreteStack))) return(false);
		ConcreteStack<?> other = (ConcreteStack<?>) obj;
		return(this.stack.equals(other.stack));
	}
	
	@Override
	public int hashCode() {
		return(stack.hashCode());
	}
	
	private Deque<T> stack;	
}